Skip to content

e87bb2cd-followup: KB docs resolve returns clean 404 for unresolvable path-shaped refs - #325

Merged
alexeygrigorev merged 1 commit into
mainfrom
fix/kb-alias-404
Nov 4, 2026
Merged

alexeygrigorev merged 1 commit into
mainfrom
fix/kb-alias-404

Conversation

@alexeygrigorev

Copy link
Copy Markdown
Member

Follow-up to task e87bb2cd. Live prod bug verified 2026-11-04 ~18:37Z: kb show "00-start-here/no-such-doc" (ref contains /, matches no document) returned 500 Internal server error instead of the clean 404 that non-path refs get.

Root cause

normalizePathAlias (backend/src/docs/docRegistry.ts:417-422 on origin/main) did if (!path.endsWith('.md')) throw new Error(alias). That plain Error is not a LookupError, so resolveReference let it escape (docRegistry.ts:273-274) and resolveDoc's LookupError→404 mapping (contentApi.ts:619-631) never caught it — the catch-all turned it into a 500.

Fix (minimal)

normalizePathAlias now throws LookupError(Document reference not found: ${alias}) — the same error type already used by resolveReference for unresolvable refs. Verified every caller of resolveReference/normalizePathAlias handles LookupError (or any error) safely:

  • contentApi.ts /docs/resolve → 404 JSON (line 627); other doc routes → NotFound (lines 565, 771, 835, 847)
  • contentApi.ts:703 (code-view sop) and :967 (move parent) → bare catch → violation / 400
  • taskChecklist.ts:122 → null; :180 → 404
  • docRegistry.ts registry build (lines 158-162, 184-188) → bare catch → violation/skip (unchanged behavior)
  • canResolve (docRegistry.ts:440) → bare catch → false

Valid .md path aliases are unaffected: the throw only fires when the path does not end in .md; resolution via registry.byPath afterwards is unchanged.

Tests

  • backend/tests/docs-registry.test.ts: unknown path-shaped ref (00-start-here/no-such-doc) → LookupError with Document reference not found: ... message (not a plain Error); unknown .md path → LookupError; valid path ref still resolves.
  • backend/tests/docs-content-api.test.ts: GET /docs/resolve — path-shaped unknown ref → 404 Document reference not found (not 500); unknown dotted ref → 404 (unchanged); valid doc ref → 200; valid path alias (accounts/sops/reset-password.md) → 200 resolving to content/accounts/sops/reset-password.md.

Both touched test files pass locally; no other suites run.

Known gap (out of scope)

The Python reference implementation tools/content_tools/content_tools/doc_registry.py:293-299 has the same structure (_normalize_path_alias raises ValueError, uncaught in resolve_reference at line 153). Not touched here — this PR fixes the TS backend that serves prod.

…oc refs

normalizePathAlias threw a plain Error for path-shaped refs that do not
end in .md; that error escaped resolveReference, bypassed the
LookupError handling in every caller, and surfaced as a 500 on
/docs/resolve for any ref containing '/' matching no document. Throw
LookupError instead so all callers map it to their existing not-found
paths (404 JSON on the resolve endpoint, NotFound elsewhere, registry
violations during build). Valid .md path aliases are unaffected.

Tests: unknown path-shaped ref -> LookupError (unit) and 404 (API),
unknown dotted ref -> 404 unchanged, valid doc and valid path alias ->
200/resolved.
@alexeygrigorev
alexeygrigorev merged commit 9ab16fa into main Nov 4, 2026
4 checks passed
@alexeygrigorev
alexeygrigorev deleted the fix/kb-alias-404 branch November 5, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant